#include <string>
#include <vector>
#include <mutex>


using Buffer = std::vector<char>;

enum SocketType{
    TCP,//SOCK_STREAM = 0,
    UDP //SOCK_DGRAM
};


class CSocket{
public:
    CSocket(const std::string& localIp, int localPort,const SocketType &type,const std::string& peerIp="",int peerPort=-1);
    CSocket(int fd){m_sfd = fd;};
    ~CSocket();
    CSocket(const CSocket& other)=delete;
    //void SetAddrIn(const sockaddr_in& addrIn){m_addr = addrIn;};
   //sockaddr_in GetAddrIn()const{return m_addr;} ;
    int GetFd()const{return m_sfd;};
    bool SetLocalIPAndPort(const std::string&ip,int port)
    {
	    m_localAddrIn.sin_addr.s_addr=inet_addr(ip.c_str());//ip地址转换
    }

    bool SetPeerIPAndPort(const std::string&ip,int port)
    {
	    m_peerAddrIn.sin_addr.s_addr=inet_addr(ip.c_str());//ip地址转换
    }

    bool GetLocalIPAndPort(const std::string&ip,int& port)
    {
        return true;
    }

    bool GetPeerIPAndPort(const std::string&ip,int& port)
    {
        return true;
    }

    SocketType GetType(){return m_type == SOCK_STREAM ? SocketType::TCP : SocketType::UDP;};
    void Send(const Buffer& data) const;
    void Recv(Buffer& data) const;
    bool Listening(int blockNum);
    bool Connect();
    bool Close();

protected:
    sockaddr_in m_localAddrIn;
    sockaddr_in m_peerAddrIn;
    int m_sfd;
    SocketType m_type;

}